clear all; close all; clc


Fd = 44.2e6/4; Td = 1/Fd;
tmax = 0.001; t = 0:Td:tmax;

N_PRN = 511; T_PRN = 0.001;
PRN = sign(randn(1, N_PRN));
ind_h = fix(mod(t/T_PRN, 1)*N_PRN) + 1;
h = PRN(ind_h);

A = 2;
f0 = 3e6;
phi = pi/4;
% d=nan(1, length(t));
% m=0;
% n=nan(1, length(t));
% s = nan(1, length(t));
% for m=1:length(t) 
% d(m)=0;
% end;
u = A * h .* cos(2*pi*f0*t + phi);

for k=0:N_PRN-1
   ind_h = fix(mod((t-tmax*k/N_PRN)/T_PRN, 1)*N_PRN) +1;
   h=PRN(ind_h);
    u_op=A*h.*cos(2*pi*f0*t + phi);
    corr(k+1)=u_op*u';
end

plot(corr);









% f = A * h .* cos(2*pi*f0*(t+m*Td) + phi);
% for m=1:1000
% f = A * h .* cos(2*pi*f0*(t+m*Td) + phi);    
% for n=1:length(t)
% s(n)=u(n)*f(n);
% d(m)=d(m)+s(n)*s(n);
% end;
% d(m)=d(m)/length(t);
% end;
% plot(t,d)
